package Offer;

/**
 * 对称的二叉树
 * @author 是阿秋啊
 * @date 2022/04/05 22:20
 **/
public class Num28 {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        return helper(root.left,root.right);
    }

    private boolean helper(TreeNode l1, TreeNode l2) {
        if (l1 == null && l2 == null) {
            return true;
        }
        if (l1 == null) {
            return false;
        }
        if (l2 == null) {
            return false;
        }
        if (l1.val != l2.val) {
            return false;
        }
        return helper(l1.left,l2.right) && helper(l1.right,l2.left);
    }
}
